package com.zhengxin.one.controller;

import com.zhengxin.one.client.UserClient;
import com.zhengxin.one.common.Result;

import com.zhengxin.one.entity.entityClass.RsyTotal;
import com.zhengxin.one.entity.entityClass.RsyTotalReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
public class TextController{
    @Autowired
    private UserClient userClient;
    //发薪接口（人是云调用）
    @RequestMapping(value = "getTotal",method = RequestMethod.POST)
    public Result total(@RequestBody ArrayList<RsyTotal> info) {
        ArrayList<RsyTotalReturn> arrayList = new ArrayList<>();
        Map<String,Object> map = new HashMap<>();
        for (RsyTotal x : info) {
            String id = x.getCarid();
            String start_time = x.getStart_time();
            String end_time = x.getEnd_time();
            RsyTotalReturn back = new RsyTotalReturn();
            if(id.equals("")){
                return Result.fail("carid不能为空");
            }
            if("".equals(start_time) || "".equals(end_time)){
                return Result.fail("月份不能为空");
            }
            if (id.equals("123456")){
                back.setId(id);
                back.setCurrentSociety("");
                back.setCurrentAccumulation("");
                back.setTotolSociety("");
                back.setTotolAccumulation("");
                arrayList.add(back);
            }else{
                back.setId(id);
                back.setCurrentSociety("300");
                back.setCurrentAccumulation("400");
                back.setTotolSociety("600");
                back.setTotolAccumulation("800");
                arrayList.add(back);
            }
        }
        return Result.success(arrayList);
    }
    //feign试用
    @RequestMapping(value = "findById",method = RequestMethod.POST)
    public Result findById(@RequestBody Map map) {
        String xml ="XMLHttpRequest";
        Map info =userClient.getClientInfo(xml,map);
        return Result.success(info);
    }
    //测试是否部署好
    @RequestMapping(value = "findYou",method = RequestMethod.GET)
    public int findYoou() {
        return 1;
    }

}
